package com.gopay.cron.event.manager;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gopay.common.datasource.DBType;
import com.gopay.common.datasource.DbContextHolder;
import com.gopay.common.domain.report.Event;
import com.gopay.common.event.EventState;
import com.gopay.common.report.dao.MqEventInfoDAO;
import com.gopay.cron.service.trans.ReportConsoleTransQueryService;
import com.gopay.cron.web.vo.TransQueryResultVO;

@Service("createtEventHandlerManager")
public class CreatetEventHandlerManager implements EventHandlerManager{
    @Resource 
    private ReportConsoleTransQueryService reportConsoleTransQueryService;
    @Resource(name="mqEventInfoDAO")
    private MqEventInfoDAO mqEventInfoDAO;
    
    @Override
    @Transactional(value="reportTransactionManager")
    public void saveOrUpdateOrderAndEvent(List<TransQueryResultVO> transQueryResultList, Event e) {
        DbContextHolder.setDbType(DBType.DS_REPORT.value);
        
        reportConsoleTransQueryService.saveOrUpdateTransQueryResultList(transQueryResultList);
        Event result = mqEventInfoDAO.find(Event.class, e.getId());
        if(null != result){
            result.setStat(EventState.SUCCESS.value);
            result.setLastUpdTs(new Date());
            mqEventInfoDAO.update(result);
        }
    }

}
